//
//  JKBaseHeaderFooterView.swift
//  ZhiHuDaily-Swift
//
//  Created by albert on 2018/3/13.
//  Copyright © 2018年 安永博. All rights reserved.
//

import UIKit

class JKBaseHeaderFooterView: UITableViewHeaderFooterView {
    
    public var skinModel: String {
        
        return UserDefaults.standard.string(forKey: JKCurrentSkinModelKey) ?? JKDaySkinModelValue
    }

    // MARK: - 初始化
    
    override init(reuseIdentifier: String?) {
        super.init(reuseIdentifier: reuseIdentifier)
        
        initialization()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        
        initialization()
    }
    
    public func initialization() {
        
        NotificationCenter.default.addObserver(self, selector: #selector(updateSkin), name: NSNotification.Name(rawValue: JKSkinModelDidChangedNotification), object: nil)
    }
    
    override func didMoveToSuperview() {
        super.didMoveToSuperview()
        
        if superview == nil { return }
        
        updateSkin()
    }
    
    deinit {
        
        NotificationCenter.default.removeObserver(self)
    }
}


extension JKBaseHeaderFooterView: JKUpdateSkinProtocol {
    
    func updateSkin() {
        
        contentView.backgroundColor = (skinModel == JKNightSkinModelValue) ? JKNightSkinNavColor : JKSameRGBColor(233)
    }
}
